<script setup lang="ts">
import { computed } from 'vue'

const props = withDefaults(defineProps<{
  options: { label: string; value: any; elTagType: string; elTagClass: string }[]
  value?: number | string | string[]
  showValue: boolean
  type: 'tag' | 'text'
}>(), {
  showValue: true,
  type: 'tag',
})

const values = computed(() => Array.isArray(props.value) ? props.value : [props.value])

const unmatchs = computed(() => values.value.filter(value => !props.options.map(option => option.value).includes(value)))
</script>

<template>
  <div>
    <template v-for="(item, index) in options">
      <template v-if="values.includes(item.value)">
        <span
          v-if="type === 'text' || (item.elTagType === 'default' || item.elTagType === '') && (item.elTagClass === '' || item.elTagClass === null)"
          :key="item.value"
          :class="item.elTagClass"
        >{{ `${item.label} ` }}</span>
        <ElTag
          v-else
          :key="`${item.value}`"
          :disable-transitions="true"
          :index="index"
          :type="item.elTagType === 'primary' ? '' : item.elTagType"
          :class="item.elTagClass"
        >
          {{ `${item.label} ` }}
        </ElTag>
      </template>
    </template>
    <template v-if="unmatchs && showValue">
      <span v-for="item in unmatchs" :key="item">{{ item }}</span>
    </template>
  </div>
</template>

<style scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
</style>
